package cn.socket.chat;

import java.io.*;
import java.net.ServerSocket;
import java.net.Socket;

/**
 * 聊天程序案列 服务端
 */
public class Server {
    public static void main(String[] args) throws IOException {
        //服务端
        System.out.println("--------------------服务端启动-----------------------------");
        ServerSocket ss=new ServerSocket(10000);
        Socket s=ss.accept();
        BufferedReader br=new BufferedReader(new InputStreamReader(s.getInputStream()));
        BufferedReader read=new BufferedReader(new InputStreamReader(System.in));
        OutputStream out = s.getOutputStream();
        String line;
        while ((line= br.readLine())!=null){
            if (line.equals("bye")){
                break;
            }
            System.out.print("客户端:");
            System.out.println(line);
            //服务端写数据
            if (read!=null) {
                String data = read.readLine();
                out.write(data.getBytes(), 0, data.getBytes().length);
            }
        }
        ss.close();
    }
}
